package vip.liux.backend.adapter.web;

import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import vip.liux.application.dots.ListResultDto;
import vip.liux.application.dots.PagedResultDto;
import vip.liux.backend.application.service.product.*;
import vip.liux.contracts.shared.enums.Status;

import java.util.List;

@RestController
@RequestMapping("/api/product")
public class ProductController {

    private static final Logger log = LoggerFactory.getLogger(ProductController.class);
    private final ProductService productService;

    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    @PostMapping
    public ProductSpuDto save(@Valid @RequestBody CreateProductDto dto) {
        return productService.save(dto);
    }

    @GetMapping
    public PagedResultDto<ProductSpuDto> pageList(QueryProductDto input) {
        return productService.pageList(input);
    }

    @GetMapping("/{spu}")
    public ProductSpuDto detail(@PathVariable String spu) {
        return productService.detail(spu);
    }

    @PutMapping("/{spu}")
    public ProductSpuDto update(@PathVariable String spu, @Valid @RequestBody CreateProductDto dto) {
        return productService.update(spu, dto);
    }

    @DeleteMapping
    public void delete(@RequestBody List<String> spuList) {
        productService.delete(spuList);
    }

    @PutMapping("/status/{status}")
    public void status(@RequestBody List<String> spuList, @PathVariable Status status) {
        productService.status(spuList, status);
    }

    @GetMapping("/skuList")
    public PagedResultDto<ProductSkuDto> skuList(QueryProductDto input) {
        return productService.skuList(input);
    }

    @GetMapping("/listBySku")
    public ListResultDto<ProductSkuDto> listBySku(@RequestParam List<String> skuList) {
        return productService.listBySku(skuList);
    }
}
